package xyz.labmem.main.modular.app.other.controller

import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.*
import xyz.labmem.base.core.annotion.BusinessLog
import xyz.labmem.base.core.base.BaseVerify
import xyz.labmem.base.core.common.request.ComDelBatchReq
import xyz.labmem.base.core.common.response.ComPageAndColumnRes
import xyz.labmem.base.core.enums.LogAnnotationOpTypeEnum
import xyz.labmem.base.core.result.RP
import xyz.labmem.base.core.result.RV
import xyz.labmem.base.core.tool.isNotBlank
import xyz.labmem.base.sys.base.BaseController
import xyz.labmem.base.sys.consts.PathPrefixConst
import xyz.labmem.main.modular.app.other.entity.ModularInfo
import xyz.labmem.main.modular.app.other.mapper.ModularInfo_Mapper
import xyz.labmem.main.modular.common.pojo.FormPage
import xyz.labmem.main.modular.common.service.selectFormPage

@RestController
@Api(tags = ["各模块中心坐标"])
@RequestMapping("${PathPrefixConst.APP_PATH_PREFIX}modularInfo")
class ModularInfo_Controller  (
    private var modularinfoMapper: ModularInfo_Mapper
) : BaseController() {
    @PostMapping("page")
    @ApiOperation(value = "分页展示各模块中心坐标")
    fun page(@RequestBody @Validated(BaseVerify.page::class) req: FormPage): RP<ComPageAndColumnRes<ModularInfo>> {
        val pages = modularinfoMapper.selectPage(
            req.IPage(),
            selectFormPage<ModularInfo>(req.query)
        )
        return pageWithColumn(pages, ModularInfo::class.java)
    }
    @BusinessLog(title = "修改数据战略投送支援队伍采集_子", opType = LogAnnotationOpTypeEnum.UPDATE)
    @PostMapping("insert")
    @ApiOperation(value = "保存数据各模块中心坐标")
    fun insert(@RequestBody req: ModularInfo): RV<*> {
        req.id = "modularInfoId"
        return if (req.selectById()==null) {
            resultJudgment(req.insert())
        } else
            resultJudgment(req.updateById())
    }

    @PostMapping("selectById")
    @ApiOperation(value = "根据主键获取各模块中心坐标")
    fun selectById(@RequestBody req: ModularInfo): RV<*> {
        req.id = "modularInfoId"
        return if (req.id.isNotBlank()) {
            success(req.selectById())
        } else
            failedMsg("id不能为空")
    }

    @DeleteMapping("delBatch")
    @ApiOperation(value = "批量删除各模块中心坐标")
    fun delBatch(@RequestBody @Validated req: ComDelBatchReq): RV<*> {
        return resultJudgment(modularinfoMapper.deleteBatchIds(req.ids), "删除成功！", "没有数据被删除")
    }


}